var DataTypes = require("sequelize").DataTypes;
var _address = require("./address");
var _cart = require("./cart");
var _exercises = require("./exercises");
var _goods = require("./goods");
var _idea = require("./idea");
var _indent = require("./indent");
var _integral = require("./integral");
var _my_design = require("./my_design");
var _option = require("./option");
var _paster = require("./paster");
var _supplier = require("./supplier");
var _user = require("./user");

function initModels(sequelize) {
  var address = _address(sequelize, DataTypes);
  var cart = _cart(sequelize, DataTypes);
  var exercises = _exercises(sequelize, DataTypes);
  var goods = _goods(sequelize, DataTypes);
  var idea = _idea(sequelize, DataTypes);
  var indent = _indent(sequelize, DataTypes);
  var integral = _integral(sequelize, DataTypes);
  var my_design = _my_design(sequelize, DataTypes);
  var option = _option(sequelize, DataTypes);
  var paster = _paster(sequelize, DataTypes);
  var supplier = _supplier(sequelize, DataTypes);
  var user = _user(sequelize, DataTypes);

  goods.belongsToMany(user, { as: 'user_id_users', through: cart, foreignKey: "goods_id", otherKey: "user_id" });
  user.belongsToMany(goods, { as: 'goods_id_goods', through: cart, foreignKey: "user_id", otherKey: "goods_id" });
  option.belongsTo(exercises, { as: "exercise", foreignKey: "exercise_id"});
  exercises.hasMany(option, { as: "options", foreignKey: "exercise_id"});
  cart.belongsTo(goods, { as: "good", foreignKey: "goods_id"});
  goods.hasMany(cart, { as: "carts", foreignKey: "goods_id"});
  indent.belongsTo(goods, { as: "good", foreignKey: "goods_id"});
  goods.hasMany(indent, { as: "indents", foreignKey: "goods_id"});
  supplier.belongsTo(goods, { as: "good", foreignKey: "goods_id"});
  goods.hasMany(supplier, { as: "suppliers", foreignKey: "goods_id"});
  address.belongsTo(user, { as: "user", foreignKey: "user_id"});
  user.hasMany(address, { as: "addresses", foreignKey: "user_id"});
  cart.belongsTo(user, { as: "user", foreignKey: "user_id"});
  user.hasMany(cart, { as: "carts", foreignKey: "user_id"});
  idea.belongsTo(user, { as: "user", foreignKey: "user_id"});
  user.hasMany(idea, { as: "ideas", foreignKey: "user_id"});
  indent.belongsTo(user, { as: "user", foreignKey: "user_id"});
  user.hasMany(indent, { as: "indents", foreignKey: "user_id"});
  integral.belongsTo(user, { as: "user", foreignKey: "user_id"});
  user.hasOne(integral, { as: "integral", foreignKey: "user_id"});
  my_design.belongsTo(user, { as: "user", foreignKey: "user_id"});
  user.hasMany(my_design, { as: "my_designs", foreignKey: "user_id"});

  return {
    address,
    cart,
    exercises,
    goods,
    idea,
    indent,
    integral,
    my_design,
    option,
    paster,
    supplier,
    user,
  };
}
module.exports = initModels;
module.exports.initModels = initModels;
module.exports.default = initModels;
